<template>
  <div>
    <h1>商品详情</h1>

    <el-form style="width:600px;"  label-width="80px">
      <el-form-item label="商品名称">
        <el-input v-model="goodsDetail.name" disabled></el-input>
      </el-form-item>
      <el-form-item label="商品描述">
        <el-input v-model="goodsDetail.subtitle" disabled></el-input>
      </el-form-item>
      <el-form-item label="当前状态">
        <el-input v-model="goodsDetail.status==1?'在售':'已下架' " disabled></el-input>
      </el-form-item>
      <el-form-item label="所属分类">
        <el-select v-model="value" placeholder="请选择一级分类">
          <el-option v-for="(item,index) in options" :key="index" :label="item.label" :value="item.name">
          </el-option>
        </el-select>
        <el-select v-model="value1" placeholder="请选择二级分类">
          <el-option v-for="(item,index) in second" :key="index" :label="item.label" :value="item.name">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="商品价格">
        <div style=" width:280px;">
          <el-input placeholder="请输入内容" v-model="goodsDetail.price">
            <template slot="append">元</template>
          </el-input>
        </div>
      </el-form-item>

      <el-form-item label="商品图片">
        <template>
          <img class="img" :src="goodsDetail.mainImage" alt="">
        </template>
      </el-form-item>
      <el-form-item label="商品详情">
        <div v-html="goodsDetail.detail"></div>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { GoodsDetail, getCategory } from "@/utils/API";
export default {
  data() {
    return {
      id: 0,
      goodsDetail: {},
      value: "",
      options: [],
      second: [],
      value1: ""
    };
  },
  filters: {},
  methods: {
    async render() {
      await GoodsDetail({ productId: this.$route.params.id }).then(res => {
        console.log(res);
        this.goodsDetail = res;
      });
      await getCategory({ categoryId: 0 }).then(res => {
        console.log(res);
        this.options = res;
        this.value = this.options[0].name;
        console.log(this.value);
      });
      await getCategory({ categoryId: this.goodsDetail.parentCategoryId }).then(
        res => {
          console.log(this.goodsDetail.parentCategoryId);
          
          console.log(res);
          this.second = res;
          this.value1 = res[0].name;
        }
      );
    }
  },
  mounted() {
    console.log(this.goodsDetail.status);
    this.render();
  }
};
</script>
<style lang="scss" scoped>
.img {
  width: 100px;
  height: 100px;
}
h1 {
  font-size: 40px;
}
</style>
